<?php

require_once(dirname(__FILE__).'/Config.php');

class DB_New {
    public function load_dbh ($role) {
        in_array($role, array('mst', 'slv')) or die;

        $dbh = mysqli_init();
        if (!$dbh) {
            die('dbh init failed');
        }
        if (!$dbh->options(MYSQLI_OPT_CONNECT_TIMEOUT, 3)) {
            die('dbh set timeout failed');
        }

        if (!$dbh->real_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)) {
            die('failed connect to db');
        }
        $dbh->set_charset('utf8') or die('could not set charset');

        return $dbh;
    }
}
